package com.problem;

public class s09 {
    public static void main(String[] args) {

    }
    //https://blog.csdn.net/qq_34453300/article/details/87923756
    public static boolean isPalindromeByString(int num) {
        if (num < 0) {
            return false;
        }
        String str = String.valueOf(num);
        char[] chars = str.toCharArray();
        int len = chars.length;
        for (int i = 0; i < len; i++) {
            if (chars[i] != chars[len - i - 1]) {
                return false;
            }
        }
        return true;
    }
    public static boolean isPalindromeByString2(int x) {
        if (x < 0 || (x % 10 == 0 && x != 0)) {  //验证
            return false;
        }
        int revertedNumber = 0;
        while (x > revertedNumber) {
            revertedNumber = revertedNumber * 10 + x % 10;
            x = x / 10;
        }
        if (x == revertedNumber || x == revertedNumber / 10) {
            return true;
        } else {
            return false;
        }
    }
}
